
package com.example.photongrid;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OptionalDataException;
import java.net.Socket;

import android.util.Log;
//import java.util.Scanner;


public class ClientListeningThread implements Runnable {

private Socket socket;
//Scanner scanner;
ObjectInputStream in;
ObjectOutputStream out;
static QuadTree message = new QuadTree();
	
	
ClientListeningThread(Socket socket, ObjectInputStream getin, ObjectOutputStream getout)
{
	this.socket = socket;
	this.in = getin;
	this.out = getout;
}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		MessageServerToClient message=null;
		try {
			message = (MessageServerToClient)in.readObject();
		} catch (OptionalDataException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(message!=null){
			if(message.board == null){
				Log.i("client","Message 1 recieved" + message.player);
				StateManagerClient.playerid = message.player;
			}
			else{
				StateManagerClient.vList = message.vehicles;
				StateManagerClient.wList = message.walls;
				StateManagerClient.updateFlag = 1;
				StateManagerClient.board = message.board;
			}
		}
	}
	
}
